﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Xml.Linq;

namespace PartyCraftServer.Web
{
    public abstract class WebController
    {
        public HttpListenerContext Context { get; set; }

        protected void WriteResponse(string value)
        {
            byte[] buffer = Encoding.UTF8.GetBytes(value);
            Context.Response.ContentLength64 = buffer.Length;
            Context.Response.ContentType = "text/plain";
            Context.Response.OutputStream.Write(buffer, 0, buffer.Length);
        }

        protected void WriteXml(XDocument xml)
        {
            WriteResponse("<?xml version=\"1.0\" ?>\n" + xml.ToString());
        }

        protected void Redirect(string Url)
        {
            Context.Response.RedirectLocation = Url;
            Context.Response.StatusCode = 302;
        }
    }
}
